#ifndef _IIC_DEVICE_H_
#define	_IIC_DEVICE_H_

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/event_groups.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include "driver/i2c.h"

#define I2C_MASTER_SCL_IO           42      /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO           2      /*!< GPIO number used for I2C master data  */
#define I2C_MASTER_NUM              I2C_NUM_1                          /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
#define I2C_MASTER_FREQ_HZ          400000                     /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE   0                          /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE   0                          /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS       1000

#define WRITE_BIT 0x00          /*!< I2C master write */
#define READ_BIT 0x01           /*!< I2C master read */

#define ACK_CHECK_EN 0x1                    /*!< I2C master will check ack from slave*/
#define ACK_CHECK_DIS 0x0                   /*!< I2C master will not check ack from slave */
#define ACK_VAL 0x0                         /*!< I2C ack value */
#define NACK_VAL 0x1                        /*!< I2C nack value */

extern float TEMP_MEASUREMENT,HUM_MEASUREMENT;
extern uint8_t electric_quantity;

esp_err_t i2c_master_init(void);
esp_err_t hal_i2c_write(i2c_port_t i2c_num, uint8_t dev_addr, uint8_t *buf, int len);
esp_err_t hal_i2c_read(i2c_port_t i2c_num, uint8_t dev_addr, uint8_t *buf, int len);
esp_err_t hal_i2c_mem_write(i2c_port_t i2c_num, uint8_t dev_addr, uint8_t reg_addr, uint8_t *buf, int len);
esp_err_t hal_i2c_mem_read(i2c_port_t i2c_num, uint8_t dev_addr, uint8_t reg_addr, uint8_t *buf, int len);

#endif



